package operation;

import result.Score;
import result.ScoreList;

import java.util.Scanner;

public class StatOperation implements IOperation{
    @Override
    public void work(ScoreList scoreList) {
        System.out.println("统计成绩!!!!");
        System.out.println("请输入课程名称:");
        Scanner sc=new Scanner(System.in);
        String courseName=sc.nextLine();
        int size = scoreList.getSize();
        int average=0;
        int max=0;
        Score scores=scoreList.getScores(0);
        int min=scores.getScore();
        int cursize=0;
        for(int i=0;i<size;i++){
            Score score=scoreList.getScores(i);
            if(score.getCourseName().equals(courseName)){
                average+=score.getScore();
                cursize++;
                if(score.getScore()>max){
                    max=score.getScore();
                }
                if(score.getScore()<min){
                    min=score.getScore();
                }
            }
        }
        if(cursize==0){
            System.out.println("没有该课程成绩，请重新输入！");
            return;
        }
        average=average/cursize;
        System.out.println("平均成绩为:"+average+",最低分为:"+min+",最高分为："+max);
    }
}
